import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login3/index')
  },
  // 电商平台
  {
    path: '/reception',
    hidden: true,
    component: () => import('@/views/reception/index'),
    children: [
      {
        path: '/home',
        component: () => import('@/views/reception/home/index')
      },
      {
        path: '/receptionProduct',
        component: () => import('@/views/reception/product/index')
      },
      {
        path: '/article',
        component: () => import('@/views/reception/article/index')
      },
      {
        path: '/secureTraceability',
        component: () => import('@/views/reception/article/secureTraceability')
      },
      {
        path: '/IndustryStandards',
        component: () => import('@/views/reception/article/IndustryStandards')
      },
      {
        path: '/commerce',
        component: () => import('@/views/reception/article/commerce')
      },
      {
        path: '/about',
        component: () => import('@/views/reception/article/about')
      },
      {
        path: '/articleDetail',
        component: () => import('@/views/reception/articleDetail/index')
      },
      {
        path: '/companyJoin',
        component: () => import('@/views/reception/companyJoin/index')
      },
      {
        path: '/receptionCompany',
        component: () => import('@/views/reception/company/index')
      },
      {
        path: '/productDetail',
        component: () => import('@/views/reception/productDetail/index')
      },
      {
        path: '/categoryDetail',
        component: () => import('@/views/reception/categoryDetail/index')
      },
      {
        name: 'orderDetail',
        path: '/orderDetail',
        component: () => import('@/views/reception/orderDetail/index')
      },
      {
        name: 'trace',
        path: '/trace',
        component: () => import('@/views/reception/trace/index')
      },
      {
        path: '/manager',
        hidden: true,
        component: () => import('@/views/reception/manager/index'),
        children: [
          {
            path: '/shop-setting',
            component: () => import('@/views/reception/manager/setting/index')
          },
          {
            path: '/shop-address',
            component: () => import('@/views/reception/manager/address/index')
          },
          {
            path: '/shop-order',
            component: () => import('@/views/reception/manager/order/index')
          },
          {
            path: '/shop-cart',
            component: () => import('@/views/reception/manager/cart/index')
          },
          {
            path: '/shop-collection',
            component: () =>
              import('@/views/reception/manager/collection/index')
          },
          {
            path: '/shop-comment',
            component: () => import('@/views/reception/manager/comment/index')
          }
        ]
      }
    ]
  },
  // 大数据平台
  {
    path: '/bigdata',
    hidden: true,
    component: () => import('@/views/bigdata/index'),
    children: [
      {
        path: '/bigdata-home',
        component: () => import('@/views/bigdata/home/index')
      },
      {
        path: '/information',
        component: () => import('@/views/bigdata/article/information')
      },
      {
        path: '/report',
        component: () => import('@/views/bigdata/article/report')
      },
      {
        path: '/publicOption',
        component: () => import('@/views/bigdata/article/publicOption')
      },
      {
        path: '/bigdata-articleDetail',
        component: () => import('@/views/bigdata/article/articleDetail')
      },
      {
        path: '/bigdata-company',
        component: () => import('@/views/bigdata/company/index')
      },
      {
        path: '/bigdata-market',
        component: () => import('@/views/bigdata/market/index')
      },
      {
        path: '/exhibition',
        component: () => import('@/views/bigdata/exhibition/index')
      },
      {
        path: '/pest',
        component: () => import('@/views/bigdata/pest/index')
      }
    ]
  },
  {
    path: '/chart',
    component: () => import('@/views/bigdata/chart/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/login'
  },
  {
    path: '/dashboard',
    component: Layout,
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '动态资讯', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/documentation',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/documentation/index'),
        name: 'Documentation',
        meta: { title: '肉桂百科', icon: 'international', affix: true }
      }
    ]
  },

  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'Profile', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/disease',
    component: Layout,
    redirect: '/disease',
    alwaysShow: true, // will always show the root menu
    name: 'disease',
    meta: {
      title: '病虫害智能防控系统',
      icon: 'bug'
      // roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: 'diseasePreview',
        component: () => import('@/views/disease/diseasePreview/index'),
        name: 'diseasePreview',
        meta: {
          title: '病虫害预览'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'graphicDiagnosis',
        component: () => import('@/views/disease/graphicDiagnosis/index'),
        name: 'graphicDiagnosis',
        meta: {
          title: '图文诊断'
          // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'visualDiagnosis',
        component: () => import('@/views/disease/visualDiagnosis/index'),
        name: 'visualDiagnosis',
        meta: {
          title: '目检诊断'
          // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'intelligentDiagnosis',
        component: () => import('@/views/disease/intelligentDiagnosis/index'),
        name: 'intelligentDiagnosis',
        meta: {
          title: '智能诊断'
          // if do not set roles, means: this page does not require permission
        }
      }
    ]
  },
  {
    path: '/plant',
    component: Layout,
    redirect: '/plant',
    alwaysShow: true, // will always show the root menu
    name: 'plant',
    meta: {
      title: '农产品质量安全溯源',
      icon: 'el-icon-guide'
    },
    children: [
      {
        path: '/productionBase',
        component: () => import('@/views/trace/productionBase'),
        name: 'productionBase',
        meta: {
          title: '基地管理'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: '/seeding',
        component: () => import('@/views/trace/seeding'),
        name: 'seeding',
        meta: {
          title: '种植管理'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: '/arg',
        component: () => import('@/views/trace/arg'),
        name: 'arg',
        meta: {
          title: '农事活动'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: '/harvest',
        component: () => import('@/views/trace/harvest'),
        name: 'harvest',
        meta: {
          title: '采摘活动'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: '/process',
        component: () => import('@/views/trace/process'),
        name: 'process',
        meta: {
          title: '加工'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: '/shipping',
        component: () => import('@/views/trace/shipping'),
        name: 'shipping',
        meta: {
          title: '运输流向'
        }
      },
      {
        path: 'Ssale',
        name: 'Ssale',
        component: () => import('@/views/trace/sale/index'),
        meta: {
          title: '销售信息'
        }
      },
    ]
  },
  {
    path: '/mallManagement',
    component: Layout,
    redirect: '/mallManagement',
    alwaysShow: true, // will always show the root menu
    name: 'mallManagement',
    meta: {
      title: '商城管理',
      icon: 'el-icon-s-shop'
      // roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/mallManagement/user/index'),
        name: 'user',
        meta: {
          title: '用户管理'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'address',
        component: () => import('@/views/mallManagement/address/index'),
        name: 'address',
        meta: {
          title: '地址管理'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'product',
        component: () => import('@/views/mallManagement/product/index'),
        name: 'product',
        meta: {
          title: '商品管理'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'Order',
        component: () => import('@/views/mallManagement/order/index'),
        name: 'Order',
        meta: {
          title: '订单管理'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },

      {
        path: 'collect',
        component: () => import('@/views/mallManagement/collect/index'),
        name: 'Ssale',
        meta: {
          title: '收藏管理'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'comment',
        component: () => import('@/views/mallManagement/comment/index'),
        name: 'comment',
        meta: {
          title: '评论管理'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      }
    ]
  },
  {
    path: '/data',
    component: Layout,
    redirect: "/bigdata",
    alwaysShow: true, // will always show the root menu
    name: "bigdata",
    meta: {
      title: "数据管理",
      icon: "el-icon-s-shop",
      // roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: "productPrice",
        component: () => import("@/views/bigdata/backend/productPrice/index"),
        name: "productPrice",
        meta: {
          title: "产品价格",
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        },
      },
      {
        path: "productStatistics",
        component: () => import("@/views/bigdata/backend/productionStatistics/index"),
        name: "productStatistics",
        meta: {
          title: "生产统计",
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        },
      },
    ],
  },
  {
    path: '/article',
    component: Layout,
    redirect: "/article",
    alwaysShow: true, // will always show the root menu
    name: "article",
    meta: {
      title: "文章管理",
      icon: "el-icon-s-shop",
      // roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: "article",
        component: () => import("@/views/article/article/index"),
        name: "article",
        meta: {
          title: "文章管理",
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        },
      },
      {
        path: "articleCategory",
        component: () => import("@/views/article/articleCategory/index"),
        name: "articleCategory",
        meta: {
          title: "文章分类管理",
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        },
      },
    ],
  },
  {
    path: '/company',
    component: Layout,
    children: [
      {
        path: "index",
        component: () => import("@/views/company/index"),
        name: "company",
        meta: { title: "企业管理", icon: "international", affix: true },
      },
    ],
  },
  {
    path: '/exhibitionManager',
    component: Layout,
    children: [
      {
        path: "index",
        component: () => import("@/views/exhibitionManager/index"),
        name: "exhibitionManager",
        meta: { title: "展会管理", icon: "international", affix: true },
      },
    ],
  },
  {
    path: "/plant",
    path: '/environment',
    component: Layout,
    redirect: '/disease',
    alwaysShow: true, // will always show the root menu
    name: 'disease',
    meta: {
      title: '环境管理',
      icon: 'bug'
      // roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: 'deviceManagment',
        component: () => import('@/views/environment/deviceManagment/index'),
        name: 'deviceManagment',
        meta: {
          title: '视频监控'
          // roles: ['admin', 'editor'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'environmentalPrediction',
        component: () => import('@/views/environment/environmentalPrediction/index'),
        name: 'environmentalPrediction',
        meta: {
          title: '环境预测'
          // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'visualDiagnosis',
        component: () => import('@/views/environment/environment'),
        name: 'visualDiagnosis',
        meta: {
          title: '图表数据'
          // if do not set roles, means: this page does not require permission
        }
      }, 
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system',
    alwaysShow: true, // will always show the root menu
    name: 'system',
    meta: {
      title: '系统管理',
      icon: 'el-icon-guide'
    },
    children: [
      {
        path: '/region',
        component: () => import('@/views/system/region'),
        name: 'region',
        meta: {
          title: '区域管理'
        }
      }
    ]
  },
  /** when your routing map is too long, you can split it into small modules **/

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
